/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.invernadero.vista;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import mx.itschapala.dsw2.invernadero.BL.PaymentBLLocal;
import mx.itschapala.dsw2.invernadero.BL.StaffBLLocal;
import mx.itschapala.dsw2.invernadero.modelo.Payment;
import mx.itschapala.dsw2.invernadero.modelo.Staff;

/**
 *
 * @author Raven
 */
@ManagedBean
@SessionScoped
public class PayBean {
    @EJB
    private StaffBLLocal staffBL;
    @EJB
    private PaymentBLLocal paymentBL;
    
    
List<Payment>lista;
List<Staff> listaStaff;
private Payment pay;
private Staff staff;
private int idStaffSeleccionado;
private String accion;
private int n;
    
    /**
     * Creates a new instance of PayBean
     */
    public PayBean() {
        pay=new Payment();
    }
    
    //----------------- GET y SET--------------------

    public List<Staff> getListaStaff() {
       listaStaff=staffBL.getList();
        return listaStaff;
    }
    

    public List<Payment> getLista() {
        lista=paymentBL.getAll();
        return lista;
    }

    public PaymentBLLocal getPaymentBL() {
        return paymentBL;
    }

    public void setPaymentBL(PaymentBLLocal paymentBL) {
        this.paymentBL = paymentBL;
    }

    public Payment getPay() {
        return pay;
    }

    public void setPay(Payment pay) {
        this.pay = pay;
    }

    public int getIdStaffSeleccionado() {
        return idStaffSeleccionado;
    }

    public void setIdStaffSeleccionado(int idStaffSeleccionado) {
        this.idStaffSeleccionado = idStaffSeleccionado;
    }
    
    
    public String prepararPago()
    {
    pay.setStaffIdstaff(staffBL.findById(idStaffSeleccionado));
    System.out.println("aaaaaaaaaaaaaaaaaaaaaa");
    return "ConfirmarPago";
        
    }
    
    //-----------------Acciones------------------------------
    public String procesarAccion(){
        if(accion.equalsIgnoreCase("Nuevo")){
        paymentBL.register(pay);
        
            System.out.println("si procesa accion");
        }
        else
        if(accion.equalsIgnoreCase("Editar")){
            paymentBL.modify(pay);
        }
        else if(accion.equalsIgnoreCase("Eliminar")){
            paymentBL.delete(pay);
        }
        accion="";
    return "Trabajador";
    }
    
    
   public String limpiarAccion(){
   pay=new Payment();
   return "TrabajadorCrearEditar";
    }
//-----------------Listener------------------------------

public void prepararNuevo(ActionEvent evt){
pay=new Payment();
accion="Nuevo";

    System.out.println("prepara nuevo");
}
public void prepararEditar(ActionEvent evt)   
{
System.out.println(evt.getComponent().getClientId());
 n=Integer.parseInt(evt.getComponent().getClientId().split(":")[2]);
    System.out.println("el numero es:"+n);
    pay=lista.get(n);
    accion="Editar";
}     


public void prepararEliminar(ActionEvent evt)   
{
System.out.println(evt.getComponent().getClientId());
 n=Integer.parseInt(evt.getComponent().getClientId().split(":")[2]);
    System.out.println("el numero es:"+n);
    pay=lista.get(n);
    accion="Eliminar";
}    

    
    
    
}
